<template>
    <div>
        登录
        <el-form
                :model="ruleForm"
                :rules="rules"
                ref="ruleForm"
                label-width="100px"
                class="demo-ruleForm"
        >
            <el-form-item label="活动名称" prop="name">
                <el-input disabled v-model="ruleForm.name"></el-input>
            </el-form-item>
            <a>
                <li>456</li>
            </a>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                ruleForm: {
                    name: 'AAA',
                },
                rules: {
                    name: [{required: true, message: '请输入活动名称', trigger: 'blur'}],
                },
            }
        },
        created() {
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        let that = this
                        that.$store.dispatch('LoginByUsername', this.ruleForm.name).then(response => {
                            if (response.code === 1) {
                                that.$store.dispatch('GetUserInfo').then((res) => { // 拉取user_info
                                    //获取用户路由
                                    that.$message({
                                        message: '登录成功',
                                        type: 'success',
                                    });
                                    // this.$router.replace({path: '/one/oneIndex'})
                                    that.$router.push({path: '/'})
                                    location.reload()
                                });
                            } else {
                                this.$message.error(response.dec.msg)
                            }
                        }).catch(error => {
                            console.log(error)
                            // this.$message.error(error)
                        })

                    } else {
                        console.log('error submit!!')
                        return false
                    }
                })
            },
            resetForm(formName) {
                this.$refs[formName].resetFields()
            },
        },
    }
</script>
<style scoped lang="scss">
</style>
